//该文件用于创建vuex中最核心的文件store
//导入vuex
import Vuex from 'vuex';
//导入vue
import Vue from 'vue'
//应用vuex
Vue.use(Vuex);

//准备state --用于存储数据
const state = {
    userInfo: {
        studentDTO: {
            id: 1572874531788971153,
            username: "陈工",
            realname: "陈工",
            telephone: "15120142316",
            studentNo: 2212201438,
            gradeId: 1,
            gradeName: "小学一年级",
            avatar: "https://file.sycup.top/1315940694896021504.jpg",
            isImprove: 1,
            status: 2,
            suiteId: 0,
            suiteName: null,
            suiteStartTime: null,
            suiteEndTime: null,
            isOverdue: "1001",
            accountType: 0,
            userType: "1001"
        },
        token: null,
        expirationTime: null
    }
}

//准备actives --用于响应组件中的动作
const actions = {
    login(context, value) {
        context.commit("SET_USER_INFO", value);
    }
}
//准备mutations --用于操作data
const mutations = {
    SET_USER_INFO(state, value) {
        state.userInfo = value
    }
}

//插件
// const plugins = store => {
//     // 在Vuex初始化时从本地存储中恢复数据
//     if (localStorage.jxstate) {
//         store.replaceState(JSON.parse(localStorage.jxstate));
//     }
//
//     // 在每次Vuex状态发生变化时将数据存储在本地
//     store.subscribe((mutation, state) => {
//         localStorage.jxstate = JSON.stringify(state);
//     });
// };
//导出/暴露store
export default new Vuex.Store({
    actions, mutations, state, strict: false
})

//strict: process.env.NODE_ENV !== 'production'